﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using XiaoGang.Soft.XGWMS.COM;
using System.IO;

namespace XiaoGang.Soft.XGWMS.UI
{
    public partial class M009_STORAGE_OUTPUT : FormBase
    {
        #region 变量定义

        private readonly XGWMS.BLL.BLL_M009_STORAGE_INPUT bll_M009_STORAGE_OUTPUT;
        private readonly XGWMS.BLL.BLL_M007_GOODS bllGoods ;
        private readonly BLL.BLL_M012_MEMBER bllMember;
        private readonly MODEL.MOD_M007_GOODS modGoods;
        bool blFormLoad = false;
        int intFirstDisplayedScrollingRowIndex = 0;
        private const string dataName = "销售";

        #endregion
        
        #region 窗口初始化

        /// <summary>
        /// <p><b>方法名称</b>SetTabIndex</p>	
        /// <p><b>概要説明	:</b>画面フォーカスの遷移順の設定</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// </summary>
        private void SetTabIndex()
        {
            int intIndex = 0;
            grpTempBillInfo.TabIndex = intIndex; intIndex++;
            txtGOODS_NM1.TabIndex = intIndex; intIndex++;
            btnGoodsIDSearch.TabIndex = intIndex; intIndex++;
            txtBUSINESS_TIME.TabIndex = intIndex; intIndex++;
            txtBILL_MEMO.TabIndex = intIndex; intIndex++;
            txtUserNo.TabIndex = intIndex; intIndex++;
            cmbUserNo.TabIndex = intIndex; intIndex++;
            txtFuKuan.TabIndex = intIndex; intIndex++;
            ckbPrint.TabIndex = intIndex; intIndex++;
            btnAdd.TabIndex = intIndex; intIndex++;
            btnClear.TabIndex = intIndex; intIndex++;
            txtGOODS_NO.TabIndex = intIndex; intIndex++;
        }

        /// <summary>
        /// <p><b>方法名称</b>SetEnable</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>概要説明  :</b>画面モードのセト</p>
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        private void SetEnable()
        {
            btnGoodsIDSearch.Enabled = true;
            txtBUSINESS_TIME.Enabled = true;
            dtpBUSINESS_TIME.Enabled = true;
            grpTempBillInfo.Enabled = true;
            grdmentTempBillInfo.Enabled = true;
            btnAdd.Enabled = true;
        }

        /// <summary>
        /// <p><b>方法名称</b>ClearControl</p>	
        /// <p><b>概要説明	:</b>画面上の全項目をオールクリアする</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// </summary>
        private void ClearControl()
        {
            grdmentTempBillInfo.Rows.Clear();
            txtBILL_MEMO.Text = "";
            txtBUSINESS_TIME.Text = DateTime.Now.ToString("yyyyMMdd").Insert(4, "/").Insert(7, "/");
            dtpBUSINESS_TIME.Text = "";
            txtALLPrice.Text = "0.0";
            txtFuKuan.Text = "0.0";
            txtYinZhao.Text = "0.0";
            txtYouHui.Text = "0.0";
            txtUserNo.Text = "";
            txtGOODS_NO.Text = "";
            txtGOODS_NM1.Text = "";
            cmbUserNo.SelectedIndex = 0;
            ckbPrint.Checked = GlobalVal.globlPrint;
        }

        /// <summary>
        /// <p><b>方法名称</b>InitialGridView</p>	
        /// <p><b>概要説明	:</b>Grid初始化</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// </summary>
        private void InitialGridView()
        {
            grdmentTempBillInfo.ReadOnly = false;
            grdmentTempBillInfo.ImeMode = ImeMode.Disable;
            grdmentTempBillInfo.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            grdmentTempBillInfo.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
            grdmentTempBillInfo.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            grdmentTempBillInfo.ColumnHeadersHeight = 25;
            grdmentTempBillInfo.ColumnHeadersVisible = true;
            grdmentTempBillInfo.AllowUserToResizeColumns = true;
            grdmentTempBillInfo.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentTempBillInfo.Columns.Add("NO.", "NO.");
            grdmentTempBillInfo.Columns.Add("GOODS_ID", "商品编码");
            grdmentTempBillInfo.Columns.Add("GOODS_NM", "商品名称");
            grdmentTempBillInfo.Columns.Add("SELLING_PRICE", "单价");
            grdmentTempBillInfo.Columns.Add("Discount", "折扣");
            grdmentTempBillInfo.Columns.Add("UNITS", "数量");
            grdmentTempBillInfo.Columns.Add("ALL_PRICE", "合计");
            DataGridViewButtonColumn btnDelete = new DataGridViewButtonColumn();
            btnDelete.Text = "删除";
            btnDelete.Width = 50;
            btnDelete.HeaderText = "删除";
            grdmentTempBillInfo.Columns.Add(btnDelete);
            DataGridViewCheckBoxColumn chkRed_Black = new DataGridViewCheckBoxColumn();
            chkRed_Black.Width = 45;
            chkRed_Black.HeaderText = "冲账";
            chkRed_Black.Name = "Red_Black";
            grdmentTempBillInfo.Columns.Add(chkRed_Black);
            grdmentTempBillInfo.Columns.Add("MEMO", "备注");
            grdmentTempBillInfo.Columns["NO."].Width = 35;
            grdmentTempBillInfo.Columns["NO."].Frozen = true;
            grdmentTempBillInfo.Columns["NO."].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentTempBillInfo.Columns["NO."].ReadOnly = true;
            grdmentTempBillInfo.Columns["NO."].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentTempBillInfo.Columns["GOODS_ID"].Width = 140;
            grdmentTempBillInfo.Columns["GOODS_ID"].Frozen = true;
            grdmentTempBillInfo.Columns["GOODS_ID"].Resizable = DataGridViewTriState.False;
            grdmentTempBillInfo.Columns["GOODS_ID"].ReadOnly = true;
            grdmentTempBillInfo.Columns["GOODS_ID"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentTempBillInfo.Columns["GOODS_ID"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentTempBillInfo.Columns["GOODS_NM"].Width = 240;
            grdmentTempBillInfo.Columns["GOODS_NM"].ReadOnly = true;
            grdmentTempBillInfo.Columns["GOODS_NM"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentTempBillInfo.Columns["SELLING_PRICE"].Width = 70;
            grdmentTempBillInfo.Columns["SELLING_PRICE"].ReadOnly = false;
            grdmentTempBillInfo.Columns["SELLING_PRICE"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdmentTempBillInfo.Columns["SELLING_PRICE"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentTempBillInfo.Columns["Discount"].Width = 50;
            grdmentTempBillInfo.Columns["Discount"].ReadOnly = false;
            grdmentTempBillInfo.Columns["Discount"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdmentTempBillInfo.Columns["Discount"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentTempBillInfo.Columns["UNITS"].Width = 50;
            grdmentTempBillInfo.Columns["UNITS"].ReadOnly = false;
            grdmentTempBillInfo.Columns["UNITS"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdmentTempBillInfo.Columns["UNITS"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentTempBillInfo.Columns["ALL_PRICE"].Width = 80;
            grdmentTempBillInfo.Columns["ALL_PRICE"].ReadOnly = true;
            grdmentTempBillInfo.Columns["ALL_PRICE"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdmentTempBillInfo.Columns["ALL_PRICE"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentTempBillInfo.Columns["MEMO"].Width = 128;
            grdmentTempBillInfo.Columns["MEMO"].ReadOnly = false;
            grdmentTempBillInfo.Columns["MEMO"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentTempBillInfo.AllowUserToAddRows = false;
            grdmentTempBillInfo.AllowUserToDeleteRows = false;
            grdmentTempBillInfo.AllowUserToResizeRows = false;
            grdmentTempBillInfo.RowHeadersVisible = false;
            grdmentTempBillInfo.RowTemplate.Height = 25;
            grdmentTempBillInfo.RowTemplate.ReadOnly = false;
            grdmentTempBillInfo.RowTemplate.Resizable = DataGridViewTriState.False;
        }

        /// <summary>
        /// <p><b>方法名称</b>InitProcess</p>	
        /// <p><b>概要説明	:</b>窗口初始化</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// </summary>
        private void InitProcess()
        {
            SetTabIndex();
            SetEnable();
            InitialGridView();
            InitComBox(); 
            ClearControl();
            //txtALLPrice.Location = new Point(txtALLPrice.Location.X,txtFuKuan.Location.Y);
            //txtYinZhao.Location = new Point (txtYinZhao.Location.X,txtUserNo.Location.Y);
            //txtYouHui.Location = new Point(txtYouHui.Location.X, txtUserNo.Location.Y);
        }

        /// <summary>	
        /// <p><b>方法名称</b>GetGoodsName</p>	
        /// <p><b>概要説明  :</b>获取商品的名称</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/16</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <param name="strValue">商品ID</param> 
        /// <returns type="string">商品名称</returns>
        protected bool GetGoodsName(string strValue)
        {
            XiaoGang.Soft.XGWMS.BLL.BLL_M007_GOODS bll_M007_GOODS =
                new XiaoGang.Soft.XGWMS.BLL.BLL_M007_GOODS();
            MODEL.MOD_M007_GOODS model =
                new XiaoGang.Soft.XGWMS.MODEL.MOD_M007_GOODS();
            model.Clear();
            model.GOODS_ID = strValue.Trim();

            ReturnValue rvReturnValue = bll_M007_GOODS.GetSingleData(model);

            if (rvReturnValue.IsSuccess == false)
            {
                Method.MessageShow(rvReturnValue.ErrorID,dataName);
                return false;
            }
            if (rvReturnValue.ResultDataSet.Tables[0].Rows.Count == 0)
            {
                Method.MessageShow("W11008",dataName);
                return false;
            }

            
            return true;
        }

        /// <summary>
        /// <p><b>方法名称</b>InitComBox</p>	
        /// <p><b>概要説明	:</b>ComBoxの初期化する</p>	
        /// <p><b>作成者	:</b>wangang</p>	
        /// <p><b>作成日	:</b>2010/03/21</p>	
        /// </summary>
        private void InitComBox()
        {
            cmbUserNo.DataSource = null;
            Method.CmbDataBound("Member", cmbUserNo);
            cmbUserNo.SelectedIndex = 0;
        }

        #endregion

        #region 方法

        /// <summary>
        /// 构造函数
        /// </summary>
        public M009_STORAGE_OUTPUT()
        {
            InitializeComponent();
            bllMember = new XiaoGang.Soft.XGWMS.BLL.BLL_M012_MEMBER();
            bll_M009_STORAGE_OUTPUT = new XiaoGang.Soft.XGWMS.BLL.BLL_M009_STORAGE_INPUT();
            bllGoods = new XiaoGang.Soft.XGWMS.BLL.BLL_M007_GOODS();
            modGoods = new XiaoGang.Soft.XGWMS.MODEL.MOD_M007_GOODS();
        }

        /// <summary>
        /// <p><b>方法名称</b>CheckProcess</p>	
        /// <p><b>概要説明  :</b>画面のデータのＣＨＥＣＫ</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="string" param="strConstrolName">控件名称</param>	
        /// <returns type="Boolean">　True:成功   False:失敗 </returns>
        protected override bool CheckProcess(string strConstrolName)
        {
            switch (strConstrolName)
            {
                
                case "txtBUSINESS_TIME":
                    if (CheckProcess(txtBUSINESS_TIME.Text.Trim().Replace("/",""), enumCheckItems.DateYMD,false, null) == false)
                    {
                        txtBUSINESS_TIME.Focus();
                        return false;
                    }
                    break;
                
                case "txtBILL_MEMO":                    
                    if (Method.CheckIsIncludeSpecailChar(txtBILL_MEMO.Text.Trim())
                        == false)
                    {
                        Method.MessageShow(GlobalVal.glostrMsg,dataName);
                        txtBILL_MEMO.Focus();
                        return false;
                    }
                    if (txtBILL_MEMO.Text.Trim().Length > txtBILL_MEMO.MaxLength)
                    {
                        Method.MessageShow("W11007", dataName);
                        txtBILL_MEMO.Focus();
                        return false;
                    }
                    break;
                
                
            }

            return true;
        }

        /// <summary>	
        /// <p><b>方法名称</b>CheckProcessLoop</p>	
        /// <p><b>概要説明  :</b>画面のデータのＣＨＥＣＫ</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="string" param="strConstrolName">控件名称</param>	
        /// <returns type="Boolean">　True:成功   False:失敗 </returns>
        private bool CheckProcessLoop(enumOperation emOperation)
        {
            switch (emOperation)
            {
                case enumOperation.Initial:
                    if (CheckProcess("txtGOODS_ID") == false) return false;
                    if (CheckProcess("txtGOODS_NM") == false) return false;
                    if (CheckProcess("txtPRODUCE_DATE") == false) return false;
                    if (CheckProcess("txtOVER_PRODUCE_DATE") == false) return false;
                    if (CheckProcess("txtBUYING_PRICE") == false) return false;
                    if (CheckProcess("txtSELLING_PRICE") == false) return false;
                    if (CheckProcess("cmbSTOREROOM_ID") == false) return false;
                    if (CheckProcess("txtUNITS") == false) return false;
                    if (CheckProcess("rabBlack") == false) return false;
                    if (CheckProcess("txtSTORAGE_MEMO") == false) return false;
                    break;
                case enumOperation.Add:
                    if (CheckProcess("txtBUSINESS_TIME") == false) return false;
                    if (CheckProcess("txtBILL_MEMO") == false) return false;
                    break;
            }
            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strGoodID"></param>
        /// <param name="strGoodNM"></param>
        /// <param name="strSELLING_PRICE"></param>
        /// <param name="strDiscount"></param>
        private void AddRowToGird(string strGoodID, string strGoodNM, string strSELLING_PRICE, double strDiscount)
        {
            intFirstDisplayedScrollingRowIndex = grdmentTempBillInfo.FirstDisplayedScrollingRowIndex;
            decimal Discount = 1m;
            decimal SELLING_PRICE = 0m;
            string AllPrice = string.Empty;
            try
            {
                if (strSELLING_PRICE != "")
                {
                    SELLING_PRICE = decimal.Parse(strSELLING_PRICE);
                    //if (strDiscount != "")
                    //{
                    //    Discount = decimal.Parse(strDiscount);
                    //}
                    Discount = decimal.Parse(strDiscount.ToString());
                    AllPrice = string.Format("{0:f2}",SELLING_PRICE * Discount);
                }
            }
            catch { }
            for (int i = 0; i < grdmentTempBillInfo.Rows.Count; i++)
            
            {
                if (strGoodID.Trim() == grdmentTempBillInfo.Rows[i].Cells["GOODS_ID"].Value.ToString().Trim())
                {
                    grdmentTempBillInfo.Rows[i].Cells["GOODS_ID"].Value = strGoodID;
                    grdmentTempBillInfo.Rows[i].Cells["GOODS_NM"].Value = strGoodNM;
                    grdmentTempBillInfo.Rows[i].Cells["SELLING_PRICE"].Value = strSELLING_PRICE;
                    grdmentTempBillInfo.Rows[i].Cells["Discount"].Value = strDiscount*10;
                    int intTempUnits = 0;
                    try
                    {
                        intTempUnits = Int32.Parse(grdmentTempBillInfo.Rows[i].Cells["UNITS"].Value.ToString().Trim());
                    }
                    catch { }
                    grdmentTempBillInfo.Rows[i].Cells["UNITS"].Value = intTempUnits + 1;
                    grdmentTempBillInfo.Rows[i].Cells["ALL_PRICE"].Value = string.Format("{0:f2}", SELLING_PRICE * Discount * (intTempUnits + 1)); ;
                    //定位滚动条位置
                    grdmentTempBillInfo.FirstDisplayedScrollingRowIndex = intFirstDisplayedScrollingRowIndex;                    
                    return;
                }
            }
            grdmentTempBillInfo.Rows.Insert(grdmentTempBillInfo.Rows.Count,
                (grdmentTempBillInfo.Rows.Count + 1).ToString(),
                strGoodID.Trim(),
                strGoodNM.Trim(),
                strSELLING_PRICE.Trim(),
                strDiscount,
                1,
                AllPrice,
                "删除",
                false,
                "");
            

            grpTempBillInfo.Text = "銷售单信息" + "  共" + grdmentTempBillInfo.Rows.Count.ToString() + "条";
            //定位滚动条位置
            if (grdmentTempBillInfo.Rows.Count > 9)
            {
                grdmentTempBillInfo.FirstDisplayedScrollingRowIndex = grdmentTempBillInfo.Rows.Count - 8;
            }            
            if (grdmentTempBillInfo.Rows.Count > 9)
            {
                grdmentTempBillInfo.Columns["GOODS_NM"].Width = 223;
            }
            else
            {
                grdmentTempBillInfo.Columns["GOODS_NM"].Width = 240;
            }
        }

        /// <summary>	
        /// <p><b>方法名称</b>NumPriceFormat</p>	
        /// <p><b>概要説明  :</b>num and price date's format</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="string" param="strValue">没有格式化的字符串</param>	
        /// <returns type="string">格式化后的字符串</returns>
        protected string NumPriceFormat(string strValue)
        {
            string strTemp = strValue;
            if (strValue.Length > 8)
            {
                return strValue;
            }
            if (strValue.Length > 6)
            {
                strTemp = strValue.Substring(0, strValue.Length - 6) + ","
                    + strValue.Substring((strValue.Substring(0, strValue.Length - 6)).Length, 3)
                    + "," + strValue.Substring(strValue.Length - 3, 3);

            }
            else if (strValue.Length > 3)
            {
                strTemp = strValue.Substring(0, strValue.Length - 3) + ","
                + strValue.Substring((strValue.Substring(0, strValue.Length - 3)).Length, 3);
            }
            return strTemp;
        }

        /// <summary>	
        /// <p><b>方法名称</b>DateFormat</p>	
        /// <p><b>概要説明  :</b>date data format</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/16</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <param name="strValue">没有格式化的字符串</param> 
        /// <returns type="string">格式化后的字符串</returns>
        protected string DateFormat(string strValue)
        {
            if (strValue.Length < 8)
            {
                return strValue;
            }
            return strValue.Substring(0, 4) + "/" +
                strValue.Substring(4, 2) + "/" +
                strValue.Substring(6, 2);
        }

        /// <summary>
        /// 计算应付金额
        /// </summary>
        private void CompPro()
        {
            decimal AllPrice = 0m;
            if (grdmentTempBillInfo.Rows.Count == 0)
            {
                txtYinZhao.Text = "";
            }
            for (int i = 0; i < grdmentTempBillInfo.Rows.Count; i++)
            {
                if (grdmentTempBillInfo.Rows[i].Cells["GOODS_ID"].Value.ToString() != "")
                {
                    string strUNITS = grdmentTempBillInfo.Rows[i].Cells["UNITS"].EditedFormattedValue.ToString().Trim();
                    string strSELLING_PRICE = grdmentTempBillInfo.Rows[i].Cells["SELLING_PRICE"].EditedFormattedValue.ToString().Trim();
                    string strDiscount = grdmentTempBillInfo.Rows[i].Cells["Discount"].EditedFormattedValue.ToString().Trim();
                    decimal Discount = 1m;
                    decimal UNITS = 0m;
                    decimal SELLING_PRICE = 0m;
                    try
                    {
                        if (strDiscount != "")
                        {
                            Discount = decimal.Parse(strDiscount) / 10;
                        }
                        UNITS = Convert.ToDecimal(strUNITS);
                        SELLING_PRICE = Convert.ToDecimal(strSELLING_PRICE);
                        AllPrice += UNITS * SELLING_PRICE * Discount;
                    }
                    catch { }
                }
            }
            txtALLPrice.Text = string.Format("{0:f2}", AllPrice);
            txtFuKuan.Text = txtALLPrice.Text;

            JiSuan();
        }

        /// <summary>
        /// 计算应找金额
        /// </summary>
        private void JiSuan()
        {
            if (txtFuKuan.Text.Trim().Length == 0)
            {
                txtYinZhao.Text = "";
                txtYouHui.Text = "";
                return;
            }
            try
            {
                decimal FuKuan = Convert.ToDecimal(txtFuKuan.Text);//实际该收的金额 也算是折后的
                decimal AllPrice = Convert.ToDecimal(txtALLPrice.Text);//支付的金额
                decimal Spread = FuKuan - AllPrice;
                if (Spread == 0)
                {
                    txtYinZhao.Text = "0.00";
                    txtYouHui.Text = "0.00";
                }
                else if (Spread > 0)
                {
                    txtYinZhao.Text = Convert.ToString(Spread);
                    txtYouHui.Text = "0.00";
                }
                else
                {
                    txtYinZhao.Text = "0.00";
                    txtYouHui.Text = Convert.ToString(-Spread);
                }
            }
            catch { }
        }

        /// <summary>
        /// 打印小票
        /// </summary>
        /// <param name="strNo"></param>
        /// <returns></returns>
        private bool Print(string strNo)
        {
            //收银打印
            string operuser = GlobalVal.gloUserInfo.USER_ID;//收银员的名称，实际修改时，应该成登录者的名字即可

            #region 第一步，首先把这项订单写入数据库的表中
            //写入数据库比较简单，
            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
            //{
            //    string name = dataGridView1.Rows[i].Cells["ProName"].Value.ToString().Trim();//获取该行的物品名称
            //    string num = dataGridView1.Rows[i].Cells["ProNum"].Value.ToString().Trim();//数量
            //    string price = dataGridView1.Rows[i].Cells["ProPrice"].Value.ToString().Trim();//单价
            //    string bm = dataGridView1.Rows[i].Cells["bianma"].Value.ToString();
            //    //string SQL = "insert into T_Order()";
            //    //SqlHelper.ExecuteNonQuery(

            //}
            #endregion

            string path = Application.StartupPath.ToString() + "\\ticket.txt";//exe程序所在的路径

            #region 第二步，把这位顾客的购物单，按格式生成一个txt文件，方便第三步打印
            //StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.UTF8);
            StreamWriter sw = new StreamWriter(path, true);
            string day = DateTime.Now.ToString("yyyyMMdd");
            string time = DateTime.Now.ToString();

            #region 小票 基本格式图
            //***************小票的格式如下************************  //
            //                   霞韵美妆                         //
            //                欢迎光临新一佳超市                   //
            //                                                     //
            //                                                     //  
            // 物品                        数量       单价(￥)    //
            //---------------------------------------------------//
            //系列红山茶硬盒                 3         45.8      //
            //哆啦A梦相架小礼包              5         25.8      //
            //哆啦A梦相架小礼包              5         25.8      //
            //哆啦A梦相架小礼包              5         25.8      //
            //哆啦A梦相架小礼包              5         25.8      //
            //哆啦A梦相架小礼包              5         25.8      //
            //哆啦A梦相架小礼包              5         25.8      //
            //哆啦A梦相架小礼包              5         25.8      //
            //--------------------------------------------------//
            //           总数：              35                 // 
            //           合计：              350                //
            //           现金：              355.9              //
            //           找赎：              15                 //
            //                                                  //
            //                                                  //
            //                                                 //
            //  日期/时间       2009/10/25 14:25:15           //
            //          服务热线：0755-25145252               //
            //**************************************************//
            #endregion

            #region 拼出小票格式

            sw.WriteLine("                                                ");
            sw.WriteLine("               霞韵美妆          \t\t");
            sw.WriteLine("                                            \t\t");
            sw.WriteLine("                                                ");
            sw.WriteLine("   流水号：" + strNo);
            sw.WriteLine("   会员：" + txtUserNo.Text.Trim());
            sw.WriteLine("   商品          单价   数量     合计 ");
            sw.WriteLine("-----------------------------------------------------");
            int nums = 5;
            int prices = 8;
            int allpricess = 8;

            #region 获取DataGridView中的数据

            decimal Discount = 1m;
            decimal SELLING_PRICE = 0m;
            string name =string.Empty;//商品名称
            string price = string.Empty;//单价
            string num = string.Empty;//数量
            string allprice = string.Empty;//合计
            string discount = string.Empty;//折扣
            for (int i = 0; i < grdmentTempBillInfo.Rows.Count; i++)
            {
                Discount = 1m;
                SELLING_PRICE = 0m;
                name = grdmentTempBillInfo.Rows[i].Cells["GOODS_NM"].Value.ToString().Trim();//商品名称
                price = grdmentTempBillInfo.Rows[i].Cells["SELLING_PRICE"].Value.ToString().Trim();//单价
                num = grdmentTempBillInfo.Rows[i].Cells["UNITS"].Value.ToString().Trim();//数量
                allprice = grdmentTempBillInfo.Rows[i].Cells["ALL_PRICE"].Value.ToString().Trim();//合计
                discount = grdmentTempBillInfo.Rows[i].Cells["Discount"].Value.ToString().Trim();//折扣
                try
                {
                    if (price != "")
                    {
                        SELLING_PRICE = decimal.Parse(price);
                        if (discount != "")
                        {
                            Discount = decimal.Parse(discount) / 10;
                        }
                        price = string.Format("{0:f2}", SELLING_PRICE * Discount);
                    }
                }
                catch { }

                int pricelength = System.Text.Encoding.Default.GetBytes(price).Length;
                int numlength = System.Text.Encoding.Default.GetBytes(num).Length;
                int allpricelength = System.Text.Encoding.Default.GetBytes(allprice).Length;
                if (numlength < nums)
                {
                    num = AddLeftSpace(num, nums);
                }
                if (pricelength < prices)
                {
                    price = AddLeftSpace(price, prices);
                }
                if (allpricelength < allpricess)
                {
                    allprice = AddLeftSpace(allprice, allpricess);
                }
                sw.WriteLine(name);
                sw.WriteLine("                 " + price + "     " + num + "    " + allprice);

            }
            #endregion

            sw.WriteLine("-----------------------------------------------------");
            sw.WriteLine("           总数：                  " + grdmentTempBillInfo.Rows.Count.ToString());
            //计算合计金额：
            sw.WriteLine("           应收：                  " + txtALLPrice.Text.Trim());//合计金额
            sw.WriteLine("           实收：                  " + txtFuKuan.Text.Trim());//合计金额
            sw.WriteLine("                                         \t\t");
            sw.WriteLine("                                         \t\t");
            sw.WriteLine("日期/时间 :" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            sw.WriteLine("操作员：" + operuser);
            sw.WriteLine("                                                ");
            sw.WriteLine("                 谢谢惠顾！");
            sw.WriteLine("                                         \t\t");
            sw.WriteLine("**********************************************");
            sw.Close();
            #endregion

            #endregion

            #region 第三部，进行打印
            System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();
            PrintDialog1.AllowSomePages = true;
            PrintDialog1.ShowHelp = true;

            // 把PrintDialog的Document属性设为上面配置好的PrintDocument的实例 
            PrintDialog1.Document = docToPrint;//这是工具箱中打印的一个 组件名称
            this.docToPrint.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(docToPrint_PrintPage);

            // 调用PrintDialog的ShowDialog函数显示打印对话框 
            //DialogResult result = PrintDialog1.ShowDialog();

            //if (result == DialogResult.OK)// 弹出设置打印机，如果不需要设置，第三部可简写为   docToPrint.Print(); 则开始进行打印了
            //{
            // 开始打印 
            try
            {
                docToPrint.Print();
            }
            catch
            {
                Method.MessageShow("W11035", dataName);//打印机错误,请检查打印机是否正常！
                return false;
            }
            finally
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }

            //}
            #endregion

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            return true;
        }

        private string GetTicketInfo()
        {
            string val = "";
            string path = Application.StartupPath.ToString() + "\\ticket.txt";//exe程序所在的路径
            try
            {
                FileStream fsFile = new FileStream(path, FileMode.Open);
                /* 
                 * 讀取數據最簡单的方法是Read()。此方法將流的下一個字符作為正整數值返回， 
                 * 如果達到了流的結尾處，則返回-1。 
                 */
                StreamReader srReader = new StreamReader(fsFile);
                int iChar;
                iChar = srReader.Read();
                while (iChar != -1)
                {
                    val += (Convert.ToChar(iChar));
                    iChar = srReader.Read();
                }
                srReader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return val;
        }

        public string AddLeftSpace(string text, int length)
        {
            text = text.PadLeft(length, ' ');
            return text;
        }

        public string AddRightSpace(string text, int length)
        {
            text = text.PadRight(length, ' ');
            return text;
        }

        /// <summary>
        /// 查询商品
        /// </summary>
        private void SearchGoods()
        {
            if (GlobalVal.gloSearchGoodsForm == null)
            {
                GlobalVal.gloSearchGoodsForm = new M007_GOODS(true);
            }
            GlobalVal.gloSearchGoodsForm.ShowSearchGoodsDialog(this, "", txtGOODS_NO.Text.Trim(), txtGOODS_NM1.Text.Trim());
            if (GlobalVal.gloSelectedGoods.ItemCount>0)
            {
                AddRowToGird(GlobalVal.gloSelectedGoods.SelectedItems[0].GOODS_ID
                    , GlobalVal.gloSelectedGoods.SelectedItems[0].GOODS_NM1,
                    GlobalVal.gloSelectedGoods.SelectedItems[0].SalePrice.ToString(),
                    GlobalVal.gloSelectedGoods.SelectedItems[0].Discount);
                CompPro();
            }
        }

        #endregion

        #region 事件

        private void M009_STORAGE_OUTPUT_Load(object sender, EventArgs e)
        {
            blFormLoad = true;
            InitProcess();
            btnGoodsIDSearch.Focus();
        }
      
        private void grdmentTempBillInfo_ButtonClick(object sender, DataGridViewCellEventArgs e)
        {
            intFirstDisplayedScrollingRowIndex = grdmentTempBillInfo.FirstDisplayedScrollingRowIndex;
            int intColumnIndex = e.ColumnIndex;
            if (intColumnIndex == 7 && e.RowIndex != -1)
            {
                if (Method.MessageShow("Q22007", dataName) == DialogResult.Yes)
                {
                    grdmentTempBillInfo.Rows.RemoveAt(grdmentTempBillInfo.CurrentRow.Index);
                    grpTempBillInfo.Text = "銷售单信息" + "  共" + grdmentTempBillInfo.Rows.Count.ToString() + "条";
                    //定位滚动条位置
                    if (intFirstDisplayedScrollingRowIndex > 1)
                    {
                        grdmentTempBillInfo.FirstDisplayedScrollingRowIndex = intFirstDisplayedScrollingRowIndex-1;
                    }
                    if (0 == grdmentTempBillInfo.Rows.Count)
                    {
                        grpTempBillInfo.Text = "銷售单信息";
                    }
                    if (grdmentTempBillInfo.Rows.Count > 9)
                    {
                        grdmentTempBillInfo.Columns["GOODS_NM"].Width = 223;
                    }
                    else
                    {
                        grdmentTempBillInfo.Columns["GOODS_NM"].Width = 240;
                    }
                    CompPro();
                }
            }
        }      
       
        protected override void AllTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            base.AllTextBox_KeyDown(sender, e);
        }

        private void AllTextBox_KeyPrecess(object sender, KeyPressEventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim();
            switch (((TextBox)sender).Name)
            {
                case "txtGOODS_ID":
                    FormBase.UKeyPress(e, InputType.Tel);
                    break;
                case "txtUNITS":
                    FormBase.UKeyPress(e, InputType.Num);
                    break;
                case "txtBUSINESS_TIME":
                    FormBase.UKeyPress(e, InputType.Date);
                    break;
            }
        }

        private void AllTextBox_GotFocus(object sender, EventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim();
            switch (((TextBox)sender).Name)
            {
                case "txtGOODS_ID":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    break;
                case "txtGOODS_NM":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Hiragana;
                    break;
                case "txtUNITS":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    ((TextBox)sender).Text =
                        ((TextBox)sender).Text.Replace(",", "");
                    break;
                case "txtBUSINESS_TIME":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    ((TextBox)sender).Text =
                        ((TextBox)sender).Text.Replace("/", "");
                    break;
            }
        }

        private void AllTextBox_LostFocus(object sender, EventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim().Replace("/","");
            strValue = strValue.Replace(",", "");
            switch (((TextBox)sender).Name)
            {
                case "txtUNITS":
                    ((TextBox)sender).Text =
                        NumPriceFormat(strValue);                        
                    break;
                case "txtBUSINESS_TIME":
                    ((TextBox)sender).Text =
                        DateFormat(strValue);
                    break;
            }
        }

        private void AllButton_Click(object sender, EventArgs e)
        {
            if (Cursor.Current == Cursors.WaitCursor)
            {
                return;
            }
            Cursor.Current = Cursors.WaitCursor;

            string strButtonName = ((Button)sender).Name;

            switch (strButtonName)
            {
                #region btnGoodsIDSearch
                case "btnGoodsIDSearch":
                    {
                        SearchGoods();
                    }
                    break;
                #endregion

                #region btnAdd

                //销售
                case "btnAdd":
                    if (CheckProcessLoop(enumOperation.Add) == false)
                    {
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                    if (0 == grdmentTempBillInfo.Rows.Count)
                    {
                        Method.MessageShow("W11037", dataName);//没有要销售的商品！
                        grdmentTempBillInfo.Focus();
                        Cursor.Current = Cursors.Default;
                        return;
                    }

                    if (txtFuKuan.Text.Trim().Length<1)
                    {
                        Method.MessageShow("I11002", dataName);//请输入付款金额！
                        txtFuKuan.Focus();
                        Cursor.Current = Cursors.Default;
                        return;
                    }

                    //检查会员信息
                    if (txtUserNo.Text.Trim().Length>0)
                    {   
                        ReturnValue reValue = bllMember.GetMemberrList(txtUserNo.Text.Trim ());
                        if(!reValue.IsSuccess)
                        {
                            Method.MessageShow(reValue.ErrorID,dataName);
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                        if (reValue.ResultDataSet.Tables[0].Rows.Count < 1)
                        {
                            Method.MessageShow("W11050", dataName);//会员编号不存在！请重新输入！
                            Cursor.Current = Cursors.Default;
                            txtUserNo.Focus();
                            txtUserNo.SelectAll();
                            return;
                        }
                        else
                        {
                            lbUserNo.Text=reValue.ResultDataSet.Tables[0].Rows[0]["USER_ID"].ToString();
                        }
                    }

                    if (Method.MessageShow("Q12012", dataName) == DialogResult.Yes)//确定要进行收银打印吗?
                    {
                        string strReturn = string.Empty;
                        MODEL.MOD_M010_BILL modelBill = new XiaoGang.Soft.XGWMS.MODEL.MOD_M010_BILL();
                        modelBill.UPDATER_ID = GlobalVal.gloUserInfo.USER_ID.Trim();
                        modelBill.TERMINAL_CD = GlobalVal.gloUserInfo.TERMINAL_CD.Trim();
                        string strBillID = bll_M009_STORAGE_OUTPUT.GetBillID(modelBill);
                        if (strBillID.Trim().Length != 12)
                        {
                            Method.MessageShow(strBillID.Trim(), dataName);
                            Cursor.Current = Cursors.Default;
                            return;
                        }

                        if (ckbPrint.Checked)
                        {
                            if (!Print(strBillID))
                            {
                                return;
                            }
                        }

                        #region INSERT INTO BILL
                        
                        modelBill.TRANS_STATE = "1";
                        modelBill.BILL_ID = strBillID;
                        modelBill.IN_OUT = "1";
                        //modelBill.UNITS = Int32.Parse(grdmentTempBillInfo.Rows[i].Cells["UNITS"].Value.ToString().Replace(",", ""));
                        modelBill.BUSINESS_TIME = txtBUSINESS_TIME.Text.Trim().Replace("/", "");
                        modelBill.MEMO = txtBILL_MEMO.Text.Trim();
                        modelBill.USER_NO = lbUserNo.Text.Trim();
                        modelBill.Preferential = decimal.Parse(txtYouHui.Text.Trim() == "" ? "0" : txtYouHui.Text.Trim());
                        strReturn = bll_M009_STORAGE_OUTPUT.InsertProcess(modelBill);
                        if (strReturn.Trim() != "0")
                        {
                            Method.MessageShow(strReturn.Trim(), dataName);
                            Cursor.Current = Cursors.Default;
                            return;
                        }

                        #endregion

                        DataTable tbInsert = new DataTable();
                        DataColumn cl1 = new DataColumn("STOREROOM_ID");
                        DataColumn cl2 = new DataColumn("GOODS_ID");
                        DataColumn cl3 = new DataColumn("UNITS");
                        DataColumn cl4 = new DataColumn("PRODUCE_DATE");
                        DataColumn cl5 = new DataColumn("OVER_PRODUCE_DATE");
                        DataColumn cl6 = new DataColumn("BUYING_PRICE");
                        DataColumn cl7 = new DataColumn("SELLING_PRICE");
                        DataColumn cl8 = new DataColumn("RED_BLACK");
                        DataColumn cl9 = new DataColumn("MEMO");

                        MODEL.MOD_M009_STORAGE_INPUT modelSTORAGE = new XiaoGang.Soft.XGWMS.MODEL.MOD_M009_STORAGE_INPUT();
                        modelSTORAGE.UPDATER_ID = GlobalVal.gloUserInfo.USER_ID.Trim();
                        modelSTORAGE.TERMINAL_CD = GlobalVal.gloUserInfo.TERMINAL_CD.Trim();
                        modelSTORAGE.STORAGE_ID = "";//采番
                        modelSTORAGE.BILL_ID = strBillID;

                        string price = string.Empty;//单价
                        string discount = string.Empty;//折扣
                        decimal Price = 0m;
                        decimal Discount = 1m;

                        XGWMS.MODEL.MOD_M007_GOODS modGoods = new XiaoGang.Soft.XGWMS.MODEL.MOD_M007_GOODS();
                        modGoods.UPDATER_ID = GlobalVal.gloUserInfo.USER_ID.Trim();
                        modGoods.TERMINAL_CD = GlobalVal.gloUserInfo.TERMINAL_CD.Trim();
                        ReturnValue retuenValue;
                        for (int i = 0; i < grdmentTempBillInfo.Rows.Count; i++)
                        {
                            #region INSERT INTO STORAGE
                            
                            modelSTORAGE.STOREROOM_ID = "";
                            modelSTORAGE.UNITS = -Int32.Parse(grdmentTempBillInfo.Rows[i].Cells["UNITS"].Value.ToString().Replace(",", ""));
                            modelSTORAGE.GOODS_ID = grdmentTempBillInfo.Rows[i].Cells["GOODS_ID"].Value.ToString();
                            modelSTORAGE.MEMO = grdmentTempBillInfo.Rows[i].Cells["MEMO"].Value.ToString();
                            modelSTORAGE.PRODUCE_DATE = "";
                            modelSTORAGE.OVER_PRODUCE_DATE = "";
                            modelSTORAGE.BUYING_PRICE = 0;//进价

                            //根据折扣计算折扣后的单价
                            //**************************
                            if (grdmentTempBillInfo.Rows[i].Cells["SELLING_PRICE"].Value == null)
                            {
                                price = "";//单价
                            }
                            else
                            {
                                price = grdmentTempBillInfo.Rows[i].Cells["SELLING_PRICE"].Value.ToString().Trim();//单价
                            }
                            if (grdmentTempBillInfo.Rows[i].Cells["Discount"].Value == null)
                            {
                                discount = "";//折扣
                            }
                            else
                            {
                                discount = grdmentTempBillInfo.Rows[i].Cells["Discount"].Value.ToString().Trim();//折扣
                            }
                            Price = 0m;
                            Discount = 1m;
                            try
                            {
                                if (price != "")
                                {
                                    Price = decimal.Parse(price);
                                    if (discount != "")
                                    {
                                        Discount = decimal.Parse(discount) / 10;
                                    }
                                    price = string.Format("{0:f2}", Price * Discount);
                                }
                            }
                            catch { }
                            modelSTORAGE.SELLING_PRICE = decimal.Parse(price != "" ? price.Replace(",", "") : "-1");
                            //*****************************

                            bool blTemp = bool.Parse(grdmentTempBillInfo.Rows[i].Cells["Red_Black"].Value.ToString());
                            if (blTemp)
                            {
                                modelSTORAGE.RED_BLACK = "1";
                            }
                            else
                            {
                                modelSTORAGE.RED_BLACK = "0";
                            }
                            strReturn = bll_M009_STORAGE_OUTPUT.InsertProcess(modelSTORAGE);
                            //Message
                            if (strReturn.Trim() != "0")
                            {
                                Method.MessageShow(strReturn.Trim(), dataName);
                                Cursor.Current = Cursors.Default;
                                return;
                            }

                            #region 更改库存商品数量                            
                            
                            modGoods.UNITS = modelSTORAGE.UNITS;
                            modGoods.GOODS_ID = modelSTORAGE.GOODS_ID;
                            retuenValue = bllGoods.AddGoodsUnits(modGoods);
                            if (!retuenValue.IsSuccess)
                            {
                                Method.MessageShow(retuenValue.ErrorID, dataName);
                                return;
                            }

                            #endregion

                            #endregion
                        }                        
                        ClearControl();
                        txtGOODS_NM1.Focus();
                        txtGOODS_NM1.SelectAll();
                        grpTempBillInfo.Text = "销售单信息";
                        //ClearControl();
                    }
                    
                    break;
                #endregion
            }
            Cursor.Current = Cursors.Default;
        }

        private void cmbSTOREROOM_ID_GotFocus(object sender, EventArgs e)
        {            
            //cmbSTOREROOM_ID.SelectAll();
        }

        private void AllRichTextBox_GotFocus(object sender, EventArgs e)
        {
            string strControlName = ((RichTextBox)sender).Name;
            switch (strControlName)
            {
                //case "txtSTORAGE_MEMO":                  
                //    txtSTORAGE_MEMO.ImeMode = ImeMode.Hiragana;
                //    break;
                case "txtBILL_MEMO":                  
                    txtBILL_MEMO.ImeMode = ImeMode.Hiragana;
                    break;
            }
            
        }

        private void dtpBUSINESS_TIME_CloseUp(object sender, EventArgs e)
        {
            txtBUSINESS_TIME.Text = Method.TimeFormat( dtpBUSINESS_TIME.Value.ToString("yyyyMMdd"));
        }

        private void txtGOODS_ID_TextChanged(object sender, EventArgs e)
        {
            //txtGOODS_NM.Text = "";
        }

        private void dtpPRODUCE_DATE_KeyDown(object sender, KeyEventArgs e)
        {
            base.AllTextBox_KeyDown(sender, e);
        }

        private void dtpOVER_PRODUCE_DATE_KeyDown(object sender, KeyEventArgs e)
        {
            base.AllTextBox_KeyDown(sender, e);
        }        
        
        //protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        //{
        //    if (keyData == Keys.Enter)
        //    {
        //        isEnter = true;
        //    }
        //    return base.ProcessCmdKey(ref msg, keyData);
        //}

        private void M009_STORAGE_OUTPUT_Activated(object sender, EventArgs e)
        {
            if (!blFormLoad)
            {
                InitComBox();
            }
            blFormLoad = false;
        }

        /// <summary>
        /// Grid中修改商品数量、单价、折扣后【回车】 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void grdmentTempBillInfo_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
        {
            //if (isEnter)
            //{
                string strUNITS = grdmentTempBillInfo.CurrentRow.Cells["UNITS"].EditedFormattedValue.ToString().Trim();
                string strSELLING_PRICE = grdmentTempBillInfo.CurrentRow.Cells["SELLING_PRICE"].EditedFormattedValue.ToString().Trim();
                string strDiscount = grdmentTempBillInfo.CurrentRow.Cells["Discount"].EditedFormattedValue.ToString().Trim();
                if (strUNITS!="")
                {
                    if (!Method.CheckIsOnlyNum(strUNITS))
                    {
                        Method.MessageShow("W11039", dataName);//商品数量必须为正整数！
                        return;
                    }
                    decimal Discount = 1m;
                    decimal UNITS = 0m;
                    decimal SELLING_PRICE = 0m;
                    try {
                        UNITS = Convert.ToDecimal(strUNITS);
                        if (UNITS <= 0)
                        {
                            Method.MessageShow("W11039", dataName);//商品数量必须为正整数！
                            return;
                        }
                        if (strSELLING_PRICE != "")
                        {
                            SELLING_PRICE = Convert.ToDecimal(strSELLING_PRICE);
                        }
                        else
                        {
                            SELLING_PRICE = 0m;
                        }
                        if (SELLING_PRICE <0)
                        {
                            Method.MessageShow("W11040", dataName);//商品单价不能小于于0！
                            return;
                        }
                        if (strDiscount != "")
                        {
                            Discount = decimal.Parse(strDiscount) / 10;
                            if (Discount > 1 || Discount <= 0)
                            {
                                Method.MessageShow("W11038", dataName);//优惠折扣必须为大于0小于等于10的数字！
                                return;
                            }
                        }
                    }
                    catch
                    {
                        Method.MessageShow("W11011", dataName); //请输入数字！
                        return; 
                    }
                    grdmentTempBillInfo.Rows[e.RowIndex].Cells["ALL_PRICE"].Value = string.Format("{0:f}",UNITS * SELLING_PRICE * Discount);//更新该商品合计金额
                    CompPro();//统计下面的数据
                }
                else
                {
                    grdmentTempBillInfo.CancelEdit();
                }
            //}
        }

        private void txtFuKuan_KeyDown(object sender, KeyEventArgs e)
        {
            base.AllTextBox_KeyDown(sender, e);
        }

        private void txtFuKuan_KeyPress(object sender, KeyPressEventArgs e)
        {
            string strControlName = ((TextBox)sender).Name;
            FormBase.UKeyPress(e, InputType.Dbl);
        }

        private void txtFuKuan_TextChanged(object sender, EventArgs e)
        {
            JiSuan();
        }

        private void docToPrint_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            string text = null;
            // 信息头 
            string strTou = string.Empty;
            System.Drawing.Font printFont = new System.Drawing.Font
            ("Arial", 8, System.Drawing.FontStyle.Regular);
            System.Drawing.Font printFont1 = new System.Drawing.Font
            ("Arial", 11, System.Drawing.FontStyle.Regular);

            text = GetTicketInfo();//获取本次购物清单数据

            // 获取信息头 
            strTou = text.Substring(0, 40);

            //信息其他部分 
            text = text.Substring(40, (text.Length - 40));

            // 设置信息打印格式 
            e.Graphics.DrawString(strTou, printFont1, System.Drawing.Brushes.Black, 5, 5);
            e.Graphics.DrawString(text, printFont, System.Drawing.Brushes.Black, 10, 5);
        }        

        private void M009_STORAGE_OUTPUT_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar.ToString().Trim() == "")
            {
                txtGOODS_NO.Text = "";
                txtGOODS_NO.Focus();
            }
        }

        /// <summary>
        /// 商品名称回车
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtGOODS_NM1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                SearchGoods();
                txtGOODS_NM1.Focus();
                txtGOODS_NM1.SelectAll();
            }
        }

        /// <summary>
        /// 条码回车
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtGOODS_NO_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                if (txtGOODS_NO.Text.Trim().Length > 0)
                {
                    //查找商品
                    XiaoGang.Soft.XGWMS.BLL.BLL_M007_GOODS bll_M007_GOODS = new XiaoGang.Soft.XGWMS.BLL.BLL_M007_GOODS();
                    ReturnValue rvReturnValue = bll_M007_GOODS.GetSingleDataByNo(txtGOODS_NO.Text.Trim());
                    if (!rvReturnValue.IsSuccess)
                    {
                        Method.MessageShow(rvReturnValue.ErrorID,dataName);
                        return;
                    }
                    if (rvReturnValue.ResultDataSet.Tables[0].Rows.Count == 1)
                    {
                        AddRowToGird(rvReturnValue.ResultDataSet.Tables[0].Rows[0]["GOODS_ID"].ToString().Trim()
                            , rvReturnValue.ResultDataSet.Tables[0].Rows[0]["GOODS_NM1"].ToString().Trim()
                            , rvReturnValue.ResultDataSet.Tables[0].Rows[0]["MONEY"].ToString().Trim() == "" ? "" : string.Format("{0:f2}", decimal.Parse(rvReturnValue.ResultDataSet.Tables[0].Rows[0]["MONEY"].ToString().Trim()))
                            , rvReturnValue.ResultDataSet.Tables[0].Rows[0]["Discount"].ToString().Trim() == "" ? 1 : double.Parse(rvReturnValue.ResultDataSet.Tables[0].Rows[0]["Discount"].ToString()));
                        CompPro();
                    }
                    else if (rvReturnValue.ResultDataSet.Tables[0].Rows.Count > 1)
                    {
                        if (GlobalVal.gloSearchGoodsForm == null)
                        {
                            GlobalVal.gloSearchGoodsForm = new M007_GOODS(true);
                        }
                        GlobalVal.gloSearchGoodsForm.ShowSearchGoodsDialog(this,"",txtGOODS_NO.Text.Trim(), txtGOODS_NM1.Text.Trim());
                        if (GlobalVal.gloSelectedGoods.ItemCount > 0)
                        {
                            AddRowToGird(GlobalVal.gloSelectedGoods.SelectedItems[0].GOODS_ID
                                , GlobalVal.gloSelectedGoods.SelectedItems[0].GOODS_NM1,
                                GlobalVal.gloSelectedGoods.SelectedItems[0].SalePrice.ToString(),
                                GlobalVal.gloSelectedGoods.SelectedItems[0].Discount);
                            CompPro();
                            txtGOODS_NM1.Focus();
                        }
                    }
                }
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            ClearControl();
            txtGOODS_NM1.Focus();
        }

        private void cmbUserNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string MemberIDNo = cmbUserNo.SelectedValue.ToString().Trim();
                if (!string.IsNullOrEmpty(MemberIDNo))
                {
                    lbUserNo.Text = MemberIDNo.Substring(0, MemberIDNo.IndexOf("#") + 1);
                    txtUserNo.Text = MemberIDNo.Substring(MemberIDNo.IndexOf("#") + 1);
                }
                else
                {
                    lbUserNo.Text = "";
                    txtUserNo.Text = "";
                }
            }
            catch
            {
                txtUserNo.Text = "";
            }
        }

        /// <summary>
        /// 检索会员ID
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtUserNo_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtUserNo.Text.Trim()))
            {
                ReturnValue reValue = bllMember.GetMemberrList(txtUserNo.Text.Trim());
                if (!reValue.IsSuccess)
                {
                    Method.MessageShow(reValue.ErrorID, dataName);
                    Cursor.Current = Cursors.Default;
                    return;
                }
                if (reValue.ResultDataSet.Tables[0].Rows.Count > 0)
                {
                    lbUserNo.Text = reValue.ResultDataSet.Tables[0].Rows[0]["USER_ID"].ToString();
                }
                else
                {
                    lbUserNo.Text = "";
                }
            }
        }

        #endregion
    }
}